find the smallest and largest element from the array